﻿/**********************  此代码是由代码生成器生成，生成时间： 2012/12/4 21:29:00  ************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using CRM.Entity.Extra;
using CRM.Entity;
using CRM.DAL;
using CRM.Entity.Page;
using CRM.Index.IProvider;
using System.Configuration;
using System.ServiceModel.Description;
using System.Xml;

namespace CRM.Controller
{
    public partial class ArticleInfoController
    {
        static readonly string address = ConfigurationManager.AppSettings["address"];

        ArticleInfoDAL  articleInfoDAL = new  ArticleInfoDAL();

        ChannelFactory<IProviderService> channelFactory;

        public ArticleInfoController()
        {
             var bindind = new NetTcpBinding();
             bindind.ReaderQuotas = new XmlDictionaryReaderQuotas() { MaxStringContentLength = 2147483647 };
             channelFactory = new ChannelFactory<IProviderService>(bindind, new EndpointAddress(new Uri(address)));             
        }

        public ArticleInfoPage GetList(PageInfo page)
        {
            ArticleInfoPage list = new ArticleInfoPage();

            try
            {
                list = channelFactory.CreateChannel().ArticleInfo_Page(page);                
            }
            catch (Exception ex)
            {
                throw;
            }
            return list;
        }
        
        /*********************************** ArticleInfoExtra **************************************/
        public ArticleInfoExtraPage GetListExtra(PageInfo page,int articleType)
        {
            ArticleInfoExtraPage list = new ArticleInfoExtraPage();

            try
            {
              list = channelFactory.CreateChannel().ArticleInfoExtra_Page(page,articleType);
            }
            catch (Exception ex)
            {
                throw;
            }
            return list;
        }

        public ArticleInfoPage GetListTop(int top)
        {
            ArticleInfoPage list = new ArticleInfoPage();

            try
            {
                list = channelFactory.CreateChannel().ArticleInfo_Top(top);
            }
            catch (Exception ex)
            {
                throw;
            }

            return list;
        }

        public ArticleInfo GetSingle(Int32 id)
        { 
          try
           {
                var single = channelFactory.CreateChannel().ArticleInfo_Single(id);

                return single;
           }
          catch (Exception ex)
          {
             throw;
          }
        }

        public bool Add(ArticleInfo articleInfo)
        {
            bool isSuccess = false;

            try
            {
                articleInfo.CreateTime = DateTime.Now;
                
                isSuccess = articleInfoDAL.ArticleInfo_Add(articleInfo);
            
                if(!isSuccess)
                 return false;
               
                isSuccess=channelFactory.CreateChannel().ArticleInfo_Insert(articleInfo);

            }
            catch (Exception ex)
            {
                throw;
            }

            return isSuccess;
        }

        public bool Update(ArticleInfo articleInfo)
        {
            bool isSuccess = false;

            try
            {
                isSuccess = articleInfoDAL.ArticleInfo_Update(articleInfo);
            
               if(!isSuccess)
                return false;

                isSuccess= channelFactory.CreateChannel().ArticleInfo_Update(articleInfo);
            }
            catch (Exception ex)
            {
               throw;
            }

            return isSuccess;
        }

        public bool Delete(ArticleInfo articleInfo)
        {
            bool isSuccess = false;

            try
            {
                isSuccess = articleInfoDAL.ArticleInfo_Remove(articleInfo);
            
               if(!isSuccess)
                return false;

               isSuccess= channelFactory.CreateChannel().ArticleInfo_Delete(articleInfo);

            }
            catch (Exception ex)
            {
              throw;
            }

            return isSuccess;
        }
    }
}
